/*
 * Copyright 2007 Jeffrey Palm
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class ProgressImpl implements Progress {
  final JProgressBar pb = new JProgressBar();
  final JLabel lab = new JLabel("Idle...");
  final JButton cancel = new JButton(new AbstractAction("Cancel") {
      public void actionPerformed(ActionEvent e) {
        if (finder == null) {
          System.exit(0);
        } else {
          finder.cancel();
        }
      }
    });
  private Finder finder;
  void setFinder(Finder finder) {this.finder = finder;}
  public void update(String msg, int inc) {
    String s = (finder != null ? finder.name() + ": " : "") + msg;
    System.out.println(inc + ":" + s);
    pb.setString(s);
    lab.setText(s);
    pb.setValue(pb.getValue()+inc);
    pb.repaint();
    lab.repaint();
  }
  public void inc() {
    pb.setValue(pb.getValue()+1);
  }
  public void reset() {
    pb.setValue(0);
  }
  public void setMax(int max) {
    reset();
    pb.setMaximum(max);
  }
}
